<template>
  <div>

    <!--    主体表格-->
    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="数据编号" width="180"></el-table-column>
        <el-table-column prop="motionDetected" label="人员活动" width="180"></el-table-column>
        <el-table-column prop="location" label="传感器位置"></el-table-column>
        <el-table-column prop="createTime" label="采集时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-popconfirm title="这是一段内容确定删除吗？" @confirm="remove(scope.row.id)">
              <el-button slot="reference" size="small" type="danger">删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </div>



    <!--    分页功能-->
    <div style="margin-top: 15px; text-align: center">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page=params.pageNum
          :page-sizes="[5, 10, 15, 20]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total=total>
      </el-pagination>
    </div>
  </div>

</template>
<script>

import request from "@/utils/request";

export default {
  name: 'A_P_InfraredSensor',
  data() {
    return {
      tableData: [],
      params:{
        location:'',
        pageNum:1,
        pageSize:5,
      },
      total:0,
      dialogFormVisible:false,
      //将登录用户信息取出
      user:localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
    }

  },
  created() {
    this.findBySearchOfINS();
  },
  methods: {
    findBySearchOfINS(){
      request.get("INS/findBySearchOfINS",{params:this.params}).then(res => {
        if(res.code === '0'){
          this.tableData = res.data.list;
          this.total = res.data.total;
        }else{

        }
      })
    },
    reset(){
      this.params = {
        location:'',
        pageNum: 1,
        pageSize: 5
      }
      this.findBySearchOfINS();
    },
    remove(id){
      request.delete("INS/deleteINS/" + id).then(res => {
        if(res.code === '0'){
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.findBySearchOfINS();
        }else{
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    handleSizeChange(pageSize) {
      this.params.pageSize = pageSize;
      this.findBySearchOfINS();
    },
    handleCurrentChange(pageNum) {
      this.params.pageNum = pageNum;
      this.findBySearchOfINS();
    }
  },
}
</script>